package com.attendance.www.hr.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.attendance.www.hr.beans.InterfaceBean;
import com.attendance.www.hr.beans.InterfaceNcBean;
import com.attendance.www.hr.service.IinterfaceService;
import com.zhangkongli.frame.core.ResultMap;

/**
 * BPM接收审批操作控制层
 * @author 侯
 *
 */
@Controller
@RequestMapping("/interface")
public class InterfaceController {
	
	@Resource
	private IinterfaceService interfaceService;
	
	/**
	 * 接收审批接口处理方法
	 * @param request 请求
	 * @return 返回true 或 false
	 */
	@RequestMapping(value = "/receiveApproval.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object receiveApproval(HttpServletRequest request,@RequestBody InterfaceBean interfaceBean) {
		if (StringUtils.isBlank(interfaceBean.getRequestType())
				|| StringUtils.isBlank(interfaceBean.getApprovalState())
				|| StringUtils.isBlank(interfaceBean.getRequestId())
				|| interfaceBean.getApprovalFecordList()==null) {
			return ResultMap.fault("0_00001", "必填项未输入，请确认！");
		}
		return interfaceService.receiveApproval(interfaceBean);
	}
	
	/**
	 * 出差接口
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/applyTravel.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object applyTravel(HttpServletRequest request,@RequestBody InterfaceBean interfaceBean){
		if (StringUtils.isBlank(interfaceBean.getEmployeeNo())
				|| StringUtils.isBlank(interfaceBean.getStartDate())
				|| StringUtils.isBlank(interfaceBean.getStartTime())
				|| StringUtils.isBlank(interfaceBean.getEndDate())
				|| StringUtils.isBlank(interfaceBean.getEndTime())
				|| StringUtils.isBlank(interfaceBean.getHours())
				|| StringUtils.isBlank(interfaceBean.getRequestDate())){
			return ResultMap.fault("0_00001", "必填项未输入，请确认！");
		}
		return interfaceService.applyTravel(interfaceBean);
	}
	
	/**
	 * 查询某个人考勤信息接口
	 * @param 
	 * @return
	 */
	@RequestMapping(value = "/getAttendanceDateByEmployeeNo.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object getAttendanceDateByEmployeeNo(HttpServletRequest request,@RequestBody InterfaceNcBean interfaceNcBean) {
		if (StringUtils.isBlank(interfaceNcBean.getEmployeeNo())
				|| StringUtils.isBlank(interfaceNcBean.getAttendanceDate())) {
			return ResultMap.fault("0_00001", "必填项未输入，请确认！");
		}
		return interfaceService.getAttendanceDateByEmployeeNo(interfaceNcBean);
	}
}
